package my_sort;

import java.util.Arrays;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/3/27 15:05
 */
public class ShellSort {
    public static void main(String[] args) {
        int[] arr = {10,6,9,3,8,2,3};
        shellSort(arr);
        System.out.println(Arrays.toString(arr));
    }
    // 希尔排序
    public static void shellSort(int[] array){
        // write code  here
        if (array.length == 0){
            return;
        }
        int gap = array.length /2 ;
        while (true){
            for (int i = gap; i < array.length; i++) {
                int x = array[i];
                int j ;
                for (j = i-gap; j >= 0 && array[j] > x ; j= j-gap) {
                    array[j+gap] = array [j];
                }

                array[j+gap] = x ;
            }
            if (gap==1){
                break;
            }
            gap /= 2;
        }

    }
}
